import requests

from geektime_0.service.litemall.api.api_base import ApiBase
from geektime_0.service.litemall.config.base_data import url


class GoodsHttpApi(ApiBase):

    # 查看商品详情
    def get_goods_detail(self, goodsId):
        r = requests.get(
            f'{url}/wx/goods/detail',
            params = {'id': goodsId},
            headers = {'X-Litemall-Token': self.session.get_token()}
        )
        return r.json()['data']['productList'][0]['id']

    # 加入购物车
    def add_cart(self, goodsId, productId, number):
        r = requests.post(
            f'{url}/wx/cart/add',
            json = {'goodsId': goodsId, 'productId': productId, 'number': number},
            headers = {'X-Litemall-Token': self.session.get_token()}
        )
        return r
